<template>
	<view>
		<uni-title title="主线任务名" type="h2" align="center"></uni-title>
		<uni-card title="主线任务规则介绍" thumbnail=""  note="Tips">
			<text>{{ text }}</text>
		</uni-card>
		<uni-section title="投资指标" sub-title="" type="line">
			<uni-list>
				<uni-list-item title="总用户数" :rightText="`${investIndicator.totalUser}`"></uni-list-item>
				<uni-list-item title="总投资额" :rightText="`${investIndicator.totalAmount}`"></uni-list-item>
				<uni-list-item title="总收益金额" :rightText="`${investIndicator.totalProfit}`"></uni-list-item>
				<uni-list-item title="有效用户数" :rightText="`${investIndicator.validUser}`"></uni-list-item>
			</uni-list>
		</uni-section>
		<uni-section title="当前任务完成情况" sub-title="" type="line">
			<uni-list>
				<uni-list-item title="总投资额" rightText="1000"></uni-list-item>
				<uni-list-item title="投资期数" rightText="1"></uni-list-item>
				<uni-list-item title="盈利" rightText="200"></uni-list-item>
				<uni-list-item title="任务达标情况" rightText="达标"></uni-list-item>
			</uni-list>
		</uni-section>
		<uni-section title="历史上传记录列表" sub-title="" type="line">
			<uni-list>
				<uni-list-item title="上传记录1" note="2024-2-26 8:30"></uni-list-item>
				<uni-list-item title="上传记录2" note="2024-2-26 7:30"></uni-list-item>
			</uni-list>
		</uni-section>
		<view class="foot-bar">
<!-- 			<button style="margin-right: .5rem;" size="mini" @click="onShowProgress">完成情况</button> -->
			<button size="mini" type="primary" @click="onSubmitHomework">交作业</button>
		</view>
	</view>
</template>

<script setup>
import { onMounted, ref } from 'vue';
import { fetchInvestIndicator } from '../../api/adventure.js'
import { FILE_UPLOAD_URL, SESSION_KEY } from '../../utils/constant.js'

const tab = ref("main")
const tabs = [{ text: '主线任务', value: 'main'}, { text: '建设中', value: 'developing'}]

const text = ref('HBuilder，900万开发者选择的IDE\nMUI，轻巧、漂亮的前端开源框架')
const investIndicator = ref({})

const onShowProgress = () => {
	uni.navigateTo({
		url: '/pages/adventure/mainProgress'
	})
}

const onSubmitHomework = () => {
	uni.chooseImage({
		count: 1,
		success (res) {
			const { tempFilePaths  } = res
			const token = uni.getStorageSync(SESSION_KEY)
			uni.uploadFile({
				url: FILE_UPLOAD_URL + '/biz/cuserFund/homework',
				filePath: tempFilePaths [0],
				name: 'file',
				header: {
					Authorization: `wx ${token}`
				},
				success (uploadFileRes) {
					const { statusCode } = uploadFileRes
					uni.showToast({
						title: '提交成功'
					})
				}
			})
		}
	})
}

onMounted(async() => {
	const { success, data } = await fetchInvestIndicator()
	if (success) {
		investIndicator.value = data
	}
})
</script>

<style lang="scss">
.tab-container {
	margin-left: 1rem;
}
.foot-bar {
	text-align: center;
}
</style>
